From ced04ffed3b087c28e964f58a51e29563d4bce1b Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Sun, 10 Aug 2014 21:12:32 -0700 Subject: [PATCH] Support --target with `cargo test` Closes #356 --- src/bin/cargo-test.rs | 3 +- tests/test_cargo_cross_compile.rs | 53 ++++++++++++++++++++++++++++++- 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/src/bin/cargo-test.rs b/src/bin/cargo-test.rs index 522b77735..cd3628dbe 100644 --- a/src/bin/cargo-test.rs +++ b/src/bin/cargo-test.rs @@ -22,6 +22,7 @@ Usage: Options: -h, --help Print this message -j N, --jobs N The number of jobs to run in parallel + --target TRIPLE Build for the target triple -u, --update-remotes Deprecated option, use `cargo update` instead --manifest-path PATH Path to the manifest to build tests for -v, --verbose Use verbose output @@ -44,7 +45,7 @@ fn execute(options: Options, shell: &mut MultiShell) -> CliResult> { env: "test", shell: shell, jobs: options.flag_jobs, - target: None, + target: options.flag_target.as_ref().map(|s| s.as_slice()), }; let err = try!(ops::run_tests(&root, &mut compile_opts, diff --git a/tests/test_cargo_cross_compile.rs b/tests/test_cargo_cross_compile.rs index 08c4d6837..6a3bcc49f 100644 --- a/tests/test_cargo_cross_compile.rs +++ b/tests/test_cargo_cross_compile.rs @@ -7,7 +7,7 @@ use std::os; use std::path; use support::{project, execs, basic_bin_manifest}; -use support::{RUNNING, COMPILING, cargo_dir}; +use support::{RUNNING, COMPILING, DOCTEST, cargo_dir}; use hamcrest::{assert_that, existing_file}; use cargo::util::process; @@ -337,3 +337,54 @@ test!(plugin_with_extra_dylib_dep { assert_that(foo.cargo_process("cargo-build").arg("--target").arg(target), execs().with_status(0)); }) + +test!(cross_tests { + let p = project("foo") + .file("Cargo.toml", r#" + [project] + name = "foo" + authors = [] + version = "0.0.0" + "#) + .file("src/main.rs", r#" + extern crate foo; + use std::os; + fn main() { + assert_eq!(os::consts::ARCH, "x86"); + } + #[test] fn test() { main() } + "#) + .file("src/lib.rs", r#" + use std::os; + pub fn foo() { assert_eq!(os::consts::ARCH, "x86"); } + #[test] fn test_foo() { foo() } + "#); + + let target = alternate(); + assert_that(p.cargo_process("cargo-test").arg("--target").arg(target), + execs().with_status(0) + .with_stdout(format!("\ +{compiling} foo v0.0.0 ({foo}) +{running} target[..]{triple}[..]test[..]foo-[..] + +running 1 test +test test ... ok + +test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured + +{running} target[..]{triple}[..]test[..]foo-[..] + +running 1 test +test test_foo ... ok + +test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured + +{doctest} foo + +running 0 tests + +test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured + +", compiling = COMPILING, running = RUNNING, foo = p.url(), triple = target, + doctest = DOCTEST))); +}) -- 2.30.2